<?xml version="1.0" encoding="utf-8" ?>
<!-- this is a stylesheet for converting 
	 process definition into dot.exe graph description file.
	 It is used for generating process graphical representation.
-->
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns="http://www.nginn.org/WorkflowDefinition.1_0.xsd" 
    xmlns:ng="http://www.nginn.org/WorkflowDefinition.1_0.xsd"
    xmlns:str="http://exslt.org/strings"
    extension-element-prefixes="str">
	
    <xsl:output method="text" indent="yes" />
	<xsl:template match="/">
		<xsl:apply-templates select="ng:process" />
	</xsl:template>
	
	<xsl:template match="ng:process">
		digraph &quot;<xsl:value-of select="@name" />_<xsl:value-of select="@version" />&quot;  {
			compound=true;
			<xsl:apply-templates select="ng:body" />
		}
	</xsl:template>
	
	<xsl:template match="ng:body">
		<xsl:apply-templates select="ng:places" />
		<xsl:apply-templates select="ng:tasks" />
		<xsl:apply-templates select="ng:flows" />
	</xsl:template>
	
	<xsl:template match="ng:places">
		<xsl:apply-templates select="*" />
	</xsl:template>
	<xsl:template match="ng:tasks">
		<xsl:apply-templates select="*" />
	</xsl:template>
	<xsl:template match="ng:flows">
		<xsl:apply-templates select="*" />
	</xsl:template>
	
	<xsl:template match="ng:place">
		<xsl:value-of select="@id" /> [shape=circle, style=filled, fillcolor=lightblue, peripheries=1
            <xsl:if test="@label">
                ,label="<xsl:value-of select="@id" />\n<xsl:value-of select="@label" />"
            </xsl:if>];
	</xsl:template>
	
	
	
	<xsl:template match="ng:task">
		<xsl:value-of select="@id" /> [style=filled, fillcolor=yellow, color=black, peripheries=1, height=0.7, fontsize=15
			<xsl:choose>
					<xsl:when test="@type='ManualTask'">,shape=note</xsl:when>
					<xsl:when test="@type='TimerTask'">,shape=octagon</xsl:when>
					<xsl:otherwise>,shape=box</xsl:otherwise>
			</xsl:choose>
			<xsl:if test="@label">
				,label="<xsl:value-of select="@id" />\n<xsl:value-of select="@label" />"
			</xsl:if>
			<xsl:choose>
				<xsl:when test="@type='SubprocessTask'">
					,peripheries=2
				</xsl:when>
				<xsl:otherwise></xsl:otherwise>
			</xsl:choose>
        ];
	</xsl:template>
	
	<xsl:template match="ng:composite">
		subgraph &quot;cluster_<xsl:value-of select='@id' />&quot; { 
			<xsl:apply-templates select="ng:body" />
		};
	</xsl:template>
	
	<xsl:template match="ng:flow">
		<xsl:variable name="fromid" select="@from" />
		<xsl:variable name="toid" select="@to" />
		<xsl:variable name="fromnode" select="//ng:*[@id=$fromid]" />
		<xsl:variable name="tonode" select="//ng:*[@id=$toid]" />
		<xsl:value-of select="@from" /> -&gt; <xsl:value-of select="@to" /> [
		<xsl:if test="@label">
			label="<xsl:value-of select="@id" />\n<xsl:value-of select="@label" />",
		</xsl:if>
		<xsl:choose>
				<xsl:when test="$fromnode/@splitType = 'XOR'">arrowtail=diamond</xsl:when>
				<xsl:when test="$fromnode/@splitType = 'OR'">arrowtail=odiamond</xsl:when>
				<xsl:otherwise>arrowtail=none</xsl:otherwise>
		</xsl:choose>,
		<xsl:choose>
				<xsl:when test="$tonode/@joinType = 'XOR'">arrowhead=open</xsl:when>
				<xsl:when test="$tonode/@joinType = 'OR'">arrowhead=empty</xsl:when>
				<xsl:otherwise>arrowhead=normal</xsl:otherwise>
		</xsl:choose>
		];
	</xsl:template>

</xsl:stylesheet>
